﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DXApplicationTangche.UC.订单一览新.对账.Service;
using DevExpress.XtraGrid.Demos.util;

namespace DXApplicationTangche.UC.订单一览新.对账
{
    public partial class Form对账一览 : DevExpress.XtraEditors.XtraForm
    {
        private List<SalePaymentReconciliationDTO> salePaymentReconciliationDTOs = new List<SalePaymentReconciliationDTO>();
        public Form对账一览()
        {
            InitializeComponent();
        }
        private void dateTimePicker日期_CloseUp(object sender, EventArgs e)
        {
            this.查询();
        }
        private void 查询()
        {
            this.salePaymentReconciliationDTOs = 对账Service.getDailySalePaymentReconciliation(this.dateTimePicker日期.Value.ToString("yyyy-MM-dd"));
            this.gridControl销售对账一览.DataSource = this.salePaymentReconciliationDTOs;
            this.bandedGridView销售对账一览.RefreshData();
            this.bandedGridView销售对账一览.BestFitColumns();
            //  清空明细
            this.gridControl明细.DataSource = null;
            this.bandedGridView明细.RefreshData();
        }

        private void bandedGridView销售对账一览_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            //  显示当前客户的进销存明细
            this.gridControl明细.DataSource = new Model对账(this.salePaymentReconciliationDTOs[e.RowHandle]).salePaymentDetailList;
            this.bandedGridView明细.RefreshData();
            this.bandedGridView明细.BestFitColumns();
        }

        private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String mobile = FunctionHelper.GetbandedgridViewValue(this.bandedGridView销售对账一览, this.bandedGridView销售对账一览.FocusedRowHandle, "mobile").ToString();
            //  筛选出当前客户的未确认进销存明细
            List<SalePaymentDetailDTO> salePaymentDetailDTOs = new Model对账(this.salePaymentReconciliationDTOs,mobile).unConfirmPaymentList;
            new Form保存销售订单支付方式(salePaymentDetailDTOs).ShowDialog();
            this.查询();
        }
    }
    public class Model对账
    {
        public List<SalePaymentDetailDTO> salePaymentDetailList = new List<SalePaymentDetailDTO>();
        public List<SalePaymentDetailDTO> unConfirmPaymentList = new List<SalePaymentDetailDTO>();
        public Model对账(SalePaymentReconciliationDTO salePaymentReconciliationDTO)
        {
            //  进项, 银联全民付
            foreach (SalePaymentDetailDTO item in salePaymentReconciliationDTO.quanminfuPaymentSalePaymentDetailDTOS)
            {
                item.build("进项", "银联全民付");
            }
            salePaymentDetailList.AddRange(salePaymentReconciliationDTO.quanminfuPaymentSalePaymentDetailDTOS);
            //  进项, 中银智慧付POS机
            foreach (SalePaymentDetailDTO item in salePaymentReconciliationDTO.bocposPaymentSalePaymentDetailDTOS)
            {
                item.build("进项", "中银智慧付POS机");
            }
            salePaymentDetailList.AddRange(salePaymentReconciliationDTO.bocposPaymentSalePaymentDetailDTOS);
            //  进项, 农行POS机
            foreach (SalePaymentDetailDTO item in salePaymentReconciliationDTO.abcposPaymentSalePaymentDetailDTOS)
            {
                item.build("进项", "农行POS机");
            }
            salePaymentDetailList.AddRange(salePaymentReconciliationDTO.abcposPaymentSalePaymentDetailDTOS);
            //  进项, 现金支付
            foreach (SalePaymentDetailDTO item in salePaymentReconciliationDTO.currencyPaymentSalePaymentDetailDTOS)
            {
                item.build("进项", "现金支付");
            }
            salePaymentDetailList.AddRange(salePaymentReconciliationDTO.currencyPaymentSalePaymentDetailDTOS);
            //  进项, 账户余额支付
            foreach (SalePaymentDetailDTO item in salePaymentReconciliationDTO.accountpayPaymentSalePaymentDetailDTOS)
            {
                item.build("进项", "账户余额支付");
            }
            salePaymentDetailList.AddRange(salePaymentReconciliationDTO.accountpayPaymentSalePaymentDetailDTOS);
            //  进项, 待确认支付方式
            foreach (SalePaymentDetailDTO item in salePaymentReconciliationDTO.unConfirmPaymentSalePaymentDetailDTOS)
            {
                item.build("进项", "待确认支付方式");
            }
            salePaymentDetailList.AddRange(salePaymentReconciliationDTO.unConfirmPaymentSalePaymentDetailDTOS);


            //  销项, 银联全民付
            foreach (SalePaymentDetailDTO item in salePaymentReconciliationDTO.quanminfuPaymentOutSalePaymentDetailDTOS)
            {
                item.build("销项", "银联全民付");
            }
            salePaymentDetailList.AddRange(salePaymentReconciliationDTO.quanminfuPaymentOutSalePaymentDetailDTOS);
            //  销项, 中银智慧付POS机
            foreach (SalePaymentDetailDTO item in salePaymentReconciliationDTO.bocposPaymentOutSalePaymentDetailDTOS)
            {
                item.build("销项", "中银智慧付POS机");
            }
            salePaymentDetailList.AddRange(salePaymentReconciliationDTO.bocposPaymentOutSalePaymentDetailDTOS);
            //  销项, 农行POS机
            foreach (SalePaymentDetailDTO item in salePaymentReconciliationDTO.abcposPaymentOutSalePaymentDetailDTOS)
            {
                item.build("销项", "农行POS机");
            }
            salePaymentDetailList.AddRange(salePaymentReconciliationDTO.abcposPaymentOutSalePaymentDetailDTOS);
            //  销项, 现金支付
            foreach (SalePaymentDetailDTO item in salePaymentReconciliationDTO.currencyPaymentOutSalePaymentDetailDTOS)
            {
                item.build("销项", "现金支付");
            }
            salePaymentDetailList.AddRange(salePaymentReconciliationDTO.currencyPaymentOutSalePaymentDetailDTOS);
            //  销项, 账户余额支付
            foreach (SalePaymentDetailDTO item in salePaymentReconciliationDTO.accountpayPaymentOutSalePaymentDetailDTOS)
            {
                item.build("销项", "账户余额支付");
            }
            salePaymentDetailList.AddRange(salePaymentReconciliationDTO.accountpayPaymentOutSalePaymentDetailDTOS);
            //  销项, 待确认支付方式
            foreach (SalePaymentDetailDTO item in salePaymentReconciliationDTO.unConfirmPaymentOutSalePaymentDetailDTOS)
            {
                item.build("销项", "待确认支付方式");
            }
            salePaymentDetailList.AddRange(salePaymentReconciliationDTO.unConfirmPaymentOutSalePaymentDetailDTOS);
        }
        public Model对账(List<SalePaymentReconciliationDTO> salePaymentReconciliationDTOs, String mobile)
        {
            foreach (SalePaymentReconciliationDTO item in salePaymentReconciliationDTOs)
            {
                if (mobile.Equals(item.mobile))
                {
                    this.unConfirmPaymentList.AddRange(item.unConfirmPaymentSalePaymentDetailDTOS);
                    this.unConfirmPaymentList.AddRange(item.unConfirmPaymentOutSalePaymentDetailDTOS);
                    break;
                }
            }
        }
    }
}